package org.example.demo4.controller.freight;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.mybatisflex.core.paginate.Page;
import org.apache.ibatis.type.JdbcType;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.example.demo4.service.FreightOaService;
import org.example.demo4.model.FreightOaEntity;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;
import java.util.List;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 控制层。
 *
 * @author mybatis-flex-helper automatic generation
 * @since 1.0
 */
@RestController
@RequestMapping("/freightOa")
@Tag(name = "oa流程")
public class FreightOaController {

    @Autowired
    private FreightOaService freightOaService;

    /**
     * 添加
     *
     * @param freightOa
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("/save")
    @Operation(summary = "添加")
    @ApiOperationSupport(order = 3)
    @Parameters(value = {
            @Parameter(name = "oaId", description = "oa流程表主键"),

            @Parameter(name = "requestId", description = "oa流程id"),

            @Parameter(name = "adjustmentType", description = "调整类型 0：新增  1：修改"),

            @Parameter(name = "adjustmentNum", description = "调整数量"),

            @Parameter(name = "freightType", description = "货运类型（专车，快运-按体积，快运-按重量，快递-按体积，固定包月）"),

            @Parameter(name = "requestStatus", description = "oa流程状态，0：审批中  1：审批拒绝  2：审批通过"),

            @Parameter(name = "requestPassTime", description = "审批通过时间"),

            @Parameter(name = "status", description = "启用状态（0正常 1停用）"),

            @Parameter(name = "createBy", description = "创建者"),

            @Parameter(name = "createTime", description = "创建时间"),

            @Parameter(name = "updateBy", description = "更新者"),

            @Parameter(name = "updateTime", description = "更新时间"),

            @Parameter(name = "remark", description = "备注")
    })
    public boolean save(@RequestBody FreightOaEntity freightOa) {
        return freightOaService.save(freightOa);
    }


    /**
     * 根据主键删除
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @DeleteMapping("/remove/{id}")
    @Operation(summary = "根据主键删除")
    @ApiOperationSupport(order = 5)
    @Parameters(value = {
            @Parameter(name = "oaId", description = "oa流程表主键", required = true)
    })
    public boolean remove(@PathVariable Serializable id) {
        return freightOaService.removeById(id);
    }


    /**
     * 根据主键更新
     *
     * @param freightOa
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PutMapping("/update")
    @Operation(summary = "根据主键更新")
    @ApiOperationSupport(order = 4)
    @Parameters(value = {
            @Parameter(name = "oaId", description = "oa流程表主键", required = true),

            @Parameter(name = "requestId", description = "oa流程id"),

            @Parameter(name = "adjustmentType", description = "调整类型 0：新增  1：修改"),

            @Parameter(name = "adjustmentNum", description = "调整数量"),

            @Parameter(name = "freightType", description = "货运类型（专车，快运-按体积，快运-按重量，快递-按体积，固定包月）"),

            @Parameter(name = "requestStatus", description = "oa流程状态，0：审批中  1：审批拒绝  2：审批通过"),

            @Parameter(name = "requestPassTime", description = "审批通过时间"),

            @Parameter(name = "status", description = "启用状态（0正常 1停用）"),

            @Parameter(name = "createBy", description = "创建者"),

            @Parameter(name = "createTime", description = "创建时间"),

            @Parameter(name = "updateBy", description = "更新者"),

            @Parameter(name = "updateTime", description = "更新时间"),

            @Parameter(name = "remark", description = "备注")
    })
    public boolean update(@RequestBody FreightOaEntity freightOa) {
        return freightOaService.updateById(freightOa);
    }


    /**
     * 查询所有
     *
     * @return 所有数据
     */
    @GetMapping("/list")
    @Operation(summary = "查询所有")
    @ApiOperationSupport(order = 6)
    public List<FreightOaEntity> list() {
        return freightOaService.list();
    }

    /**
     * 根据主键获取详细信息。
     *
     * @param id freightOa主键
     * @return 详情
     */
    @GetMapping("/getInfo/{id}")
    @Operation(summary = "根据主键获取详细信息")
    @ApiOperationSupport(order = 2)
    @Parameters(value = {
            @Parameter(name = "oaId", description = "oa流程表主键", required = true)
    })
    public FreightOaEntity getInfo(@PathVariable Serializable id) {
        return freightOaService.getById(id);
    }


    /**
     * 分页查询
     *
     * @param page 分页对象
     * @return 分页对象
     */
    @GetMapping("/page")
    @Operation(summary = "分页查询")
    @ApiOperationSupport(order = 1)
    @Parameters(value = {
            @Parameter(name = "pageNumber", description = "页码", required = true),
            @Parameter(name = "pageSize", description = "每页大小", required = true)
    })
    public Page<FreightOaEntity> page(Page<FreightOaEntity> page) {


        return freightOaService.page(page);
    }
}